<!--
 * @Author: hucc
 * @Date: 2021-10-11 14:13:20
 * @LastEditors: hucc
 * @LastEditTime: 2021-10-11 14:52:46
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue组件基础</title>
    <script src="../js/vue.js"></script>
</head>

<body>
    <div id="app">
        <my-com></my-com>
        <my-com></my-com>
        <my-com></my-com>
        <my-com></my-com>
        <!-- <my-com2></my-com2> -->
    </div>
    <script>
        //所有的组件和vue实例有且只有一个根元素/根节点
        //1.组件的定义，声明一个组件
        let component1 = {
                data() {
                    return {
                        msg: '我是子组件一'
                    }
                },
                template: `
                <div>
                <h3>{{msg}}</h3>
                <button @click="msg='新数据'">修改数据</button>
                </div>
            `
            }
            //2.组件注册
            //2.1全局注册
            //html,css不区分大小写 Vue.component() 组件名称，配置项
        Vue.component('my-com', component1);

        //1.组件的定义，声明一个组件
        let component2 = {
            data() {
                return {
                    msg: '我是子组件二'
                }
            },
            template: `
                <div>
                <h3>{{msg}}</h3>
                <my-com></my-com>
                </div>
            `
        }



        let vm = new Vue({
            el: '#app',
            data: {},
            methods: {},
            created() {},
            components: {
                //局部注册
                'my-com2': component2
            }

        })
    </script>
</body>

</html>